package com.blogs.component;

import java.util.ArrayList;

import com.blogs.entity.ChannelFeed;
import com.blogs.tools.DBSharedPreferences;
import com.cnblogs.R;
import com.cnblogs.R.color;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ChannelAdapter extends BaseAdapter{
	private  ArrayList<ChannelFeed> channelList = null;
	private ViewHolder holder;
	private Activity context = null;
	private DBSharedPreferences sp;
	private boolean isDark;
	public ChannelAdapter(Activity context, ArrayList<ChannelFeed> feedList) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.channelList = feedList;
		sp= new DBSharedPreferences(context);
	}
	public int getCount() {
		// TODO Auto-generated method stub
		return channelList.size();
	}
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return channelList.get(position);
	}
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		isDark=sp.GetIsDarkState();
		if (convertView == null ) {
			convertView = View.inflate(context, R.layout.channel_adapter_template,null);
			holder=new ViewHolder();
			holder.channel_text_tv=(TextView)convertView.findViewById(R.id.channel_text_tv);
			holder.channel_pic_iv=(ImageView)convertView.findViewById(R.id.channel_pic_iv);
			convertView.setTag(holder);
		}
	    else
	    {
	    	holder = (ViewHolder) convertView.getTag();
	    }
		holder.channel_text_tv.setText(channelList.get(position).channel_text);
		if(channelList.get(position).isBigType)
		{
			holder.channel_text_tv.setTypeface(Typeface.DEFAULT_BOLD, Typeface.BOLD);
			holder.channel_text_tv.setPadding(10, 3, 3, 0);
			holder.channel_text_tv.setTextColor(Color.parseColor("#00A2B5"));
			
		}
		else
		{
			holder.channel_text_tv.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
			holder.channel_text_tv.setPadding(30, 3, 3, 0);
			if(isDark)
			{
				holder.channel_text_tv.setTextColor(context.getResources().getColor(color.con_butom_night));
			}
			else
			{
				holder.channel_text_tv.setTextColor(Color.parseColor("#000000"));
			}
		}
//		DBSharedPreferences sp =new DBSharedPreferences(context);
		if(position==sp.GetChannelIndex())
		{
			holder.channel_pic_iv.setImageResource(R.drawable.main_popup_check_bon);
		}
		else
		{
			holder.channel_pic_iv.setImageResource(R.drawable.main_popup_check);
		}
		Log.i("ListView_position", position+"");
		return convertView;
	}
	class ViewHolder 
	{
		TextView channel_text_tv;
		ImageView channel_pic_iv;
	}
}
